package com.review.reviewsb.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.review.reviewsb.domain.Video;
import com.review.reviewsb.service.VideoService;
import com.review.reviewsb.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: reviewSb
 * @description: 视频控制器
 * @author: YaoZhiLi
 * @create: 2021-07-02 22:41
 */
//@Controller+@ResponseBody
@RestController
@RequestMapping("api/v1/pub/video")
public class VideoController {
    @Autowired
    private VideoService videoService;
//    @RequestMapping(value = "list",method = RequestMethod.GET)
    @GetMapping("list")
    public JsonData list() throws JsonProcessingException {
        List<Video> list = videoService.listVideo();
        ObjectMapper objectMapper = new ObjectMapper();
        String s = objectMapper.writeValueAsString(list);
        System.out.println(s);
        List<Video> list1 = objectMapper.readValue(s, List.class);
        System.out.println("12");
        return JsonData.buildSuccess(list1);
    }

    @PostMapping("save_video_chapter")
    public JsonData saveVideoChapter(@RequestBody Video video){
        System.out.println(video.toString());
        return JsonData.buildSuccess(videoService.saveVideo(video));
    }
}